
import { lockLists, getOpenRecordList } from '@/api/lock'

const lock = {
  state: {
    lockDataList: [],
    lockParams: {
      hoperatorId: '', // 经营者id
      storesId: '', // 门店id
      jylx: '', // 门店所属经营类型
      page: 1, // 页码
      fh: '', // 房号
      pagesize: 10 // 显示条数
    },
    lockLoading: false,
    lockTotal: 0,
    openRecordDataList: [],
    openRecordParams: {
      hoperatorId: '', // 经营者id
      storesId: '', // 门店id
      jylx: '', // 门店所属经营类型
      page: 1, // 页码
      fjh: '', // 房号
      kmrsf: '',
      ksrq: '',
      jsrq: '',
      kmsj: [],
      pagesize: 10 // 显示条数
    },
    openRecordLoading: false,
    openRecordTotal: 0
  },
  mutations: {
    setLockDataList (state, data) {
      state.lockDataList = data
    },
    setLockParams (state, data) {
      const obj = Object.assign(state.lockParams, data)
      state.lockParams = obj
    },
    setLockLoading (state, data) {
      state.lockLoading = data
    },
    setLockTotal (state, data) {
      state.lockTotal = data
    },
    setOpenRecordDataList (state, data) {
      state.openRecordDataList = data
    },
    setOpenRecordParams (state, data) {
      const obj = Object.assign(state.openRecordParams, data)
      state.openRecordParams = obj
    },
    setOpenRecordLoading (state, data) {
      state.openRecordLoading = data
    },
    setOpenRecordTotalg (state, data) {
      state.openRecordTotal = data
    }
  },
  actions: {
    getLockLists ({ commit }, data) {
      commit('setLockLoading', true)
      return new Promise((resolve, reject) => {
        try {
          lockLists(data).then((res) => {
            commit('setLockDataList', res.data)
            // commit('setLockParams', data) 对象可以不调用方法
            commit('setLockTotal', res.count)
            commit('setLockLoading', false)
            resolve(res)
          }).catch(error => reject(error))
        } catch (error) {
          reject(error)
        }
      })
    },
    getOpenRecordList ({ commit }, data) {
      commit('setOpenRecordLoading', true)
      return new Promise((resolve, reject) => {
        try {
          getOpenRecordList(data).then((res) => {
            commit('setOpenRecordDataList', res.data)
            // commit('setOpenRecordParams', data)
            commit('setOpenRecordTotalg', res.count)
            commit('setOpenRecordLoading', false)
            resolve(res)
          }).catch(error => reject(error))
        } catch (error) {
          reject(error)
        }
      })
    }
  }
}
export default lock
